#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QLayout* pLayout = new QBoxLayout(QBoxLayout::TopToBottom, ui->groupBox);
    ui->groupBox->setLayout(pLayout);
    pCanvas = new MyCanvas(ui->groupBox,ui->tableWidget);
    pLayout->addWidget(pCanvas);
    ui->tableWidget->setRowCount(4);
    ui->txtcantpuntos->setText("800");
    ui->tableWidget->setColumnCount(7);
    ui->tableWidget->setItem(0, 0, new QTableWidgetItem("a"));
    ui->tableWidget->setItem(0, 1, new QTableWidgetItem("b"));
    ui->tableWidget->setItem(0, 2, new QTableWidgetItem("c"));
    ui->tableWidget->setItem(0, 3, new QTableWidgetItem("d"));
    ui->tableWidget->setItem(0, 4, new QTableWidgetItem("e"));
    ui->tableWidget->setItem(0, 5, new QTableWidgetItem("f"));
    ui->tableWidget->setItem(0, 6, new QTableWidgetItem("probabilidad"));

    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 5, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 6, new QTableWidgetItem("0.33"));

    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(2, 4, new QTableWidgetItem("100"));
    ui->tableWidget->setItem(2, 5, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 6, new QTableWidgetItem("0.33"));

    ui->tableWidget->setItem(3, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(3, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(3, 4, new QTableWidgetItem("100"));
    ui->tableWidget->setItem(3, 5, new QTableWidgetItem("100"));
    ui->tableWidget->setItem(3, 6, new QTableWidgetItem("0.33"));

}
MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_tableWidget_cellChanged(int row, int column)
{

}

void MainWindow::on_pushButton_clicked()
{
    this->pCanvas->pintar=true;
    this->pCanvas->cantpuntos=ui->txtcantpuntos->text().toInt();
    this->update();
}

void MainWindow::on_addbtn_clicked()
{
    ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
}

void MainWindow::on_rmvbtn_clicked()
{
    if(ui->tableWidget->rowCount()>2)
        ui->tableWidget->setRowCount(ui->tableWidget->rowCount()-1);
}

void MainWindow::on_btnhelecho_clicked()
{
    ui->tableWidget->setRowCount(5);

    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 3, new QTableWidgetItem("0.16"));
    ui->tableWidget->setItem(1, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 5, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 6, new QTableWidgetItem("0.01"));

    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("0.85"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("0.04"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("-0.04"));
    ui->tableWidget->setItem(2, 3, new QTableWidgetItem("0.85"));
    ui->tableWidget->setItem(2, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 5, new QTableWidgetItem("1.6"));
    ui->tableWidget->setItem(2, 6, new QTableWidgetItem("0.85"));

    ui->tableWidget->setItem(3, 0, new QTableWidgetItem("0.2"));
    ui->tableWidget->setItem(3, 1, new QTableWidgetItem("-0.26"));
    ui->tableWidget->setItem(3, 2, new QTableWidgetItem("0.23"));
    ui->tableWidget->setItem(3, 3, new QTableWidgetItem("0.22"));
    ui->tableWidget->setItem(3, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 5, new QTableWidgetItem("1.6"));
    ui->tableWidget->setItem(3, 6, new QTableWidgetItem("0.07"));

    ui->tableWidget->setItem(4, 0, new QTableWidgetItem("-0.15"));
    ui->tableWidget->setItem(4, 1, new QTableWidgetItem("0.28"));
    ui->tableWidget->setItem(4, 2, new QTableWidgetItem("0.26"));
    ui->tableWidget->setItem(4, 3, new QTableWidgetItem("0.24"));
    ui->tableWidget->setItem(4, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(4, 5, new QTableWidgetItem("0.44"));
    ui->tableWidget->setItem(4, 6, new QTableWidgetItem("0.07"));
}

void MainWindow::on_btnarbol_clicked()
{
    ui->tableWidget->setRowCount(5);

    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 5, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 6, new QTableWidgetItem("0.05"));

    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("0.42"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("-0.42"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("0.42"));
    ui->tableWidget->setItem(2, 3, new QTableWidgetItem("0.42"));
    ui->tableWidget->setItem(2, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 5, new QTableWidgetItem("0.2"));
    ui->tableWidget->setItem(2, 6, new QTableWidgetItem("0.4"));

    ui->tableWidget->setItem(3, 0, new QTableWidgetItem("0.42"));
    ui->tableWidget->setItem(3, 1, new QTableWidgetItem("0.42"));
    ui->tableWidget->setItem(3, 2, new QTableWidgetItem("-0.42"));
    ui->tableWidget->setItem(3, 3, new QTableWidgetItem("0.42"));
    ui->tableWidget->setItem(3, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 5, new QTableWidgetItem("0.2"));
    ui->tableWidget->setItem(3, 6, new QTableWidgetItem("0.4"));

    ui->tableWidget->setItem(4, 0, new QTableWidgetItem("0.1"));
    ui->tableWidget->setItem(4, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(4, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(4, 3, new QTableWidgetItem("0.1"));
    ui->tableWidget->setItem(4, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(4, 5, new QTableWidgetItem("0.2"));
    ui->tableWidget->setItem(4, 6, new QTableWidgetItem("0.15"));
}

void MainWindow::on_btncuadrado_clicked()
{
    ui->tableWidget->setRowCount(5);

    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 4, new QTableWidgetItem("1"));
    ui->tableWidget->setItem(1, 5, new QTableWidgetItem("1"));
    ui->tableWidget->setItem(1, 6, new QTableWidgetItem("0.25"));

    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(2, 4, new QTableWidgetItem("50"));
    ui->tableWidget->setItem(2, 5, new QTableWidgetItem("1"));
    ui->tableWidget->setItem(2, 6, new QTableWidgetItem("0.25"));

    ui->tableWidget->setItem(3, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(3, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(3, 4, new QTableWidgetItem("1"));
    ui->tableWidget->setItem(3, 5, new QTableWidgetItem("50"));
    ui->tableWidget->setItem(3, 6, new QTableWidgetItem("0.25"));

    ui->tableWidget->setItem(4, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(4, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(4, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(4, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(4, 4, new QTableWidgetItem("50"));
    ui->tableWidget->setItem(4, 5, new QTableWidgetItem("50"));
    ui->tableWidget->setItem(4, 6, new QTableWidgetItem("0.25"));

}

void MainWindow::on_btnsierpinski_clicked()
{
    ui->tableWidget->setRowCount(4);
    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(1, 4, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 5, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(1, 6, new QTableWidgetItem("0.33"));

    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(2, 4, new QTableWidgetItem("100"));
    ui->tableWidget->setItem(2, 5, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(2, 6, new QTableWidgetItem("0.33"));

    ui->tableWidget->setItem(3, 0, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(3, 1, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 2, new QTableWidgetItem("0"));
    ui->tableWidget->setItem(3, 3, new QTableWidgetItem("0.5"));
    ui->tableWidget->setItem(3, 4, new QTableWidgetItem("100"));
    ui->tableWidget->setItem(3, 5, new QTableWidgetItem("100"));
    ui->tableWidget->setItem(3, 6, new QTableWidgetItem("0.33"));
}
